#include "FrontendState.h"


FrontendState::FrontendState(GameContext& gc)
	: GameState(gc)
	, mTitleMusic()
{
}


FrontendState::~FrontendState(void)
{
}


void FrontendState:: Load()
{
	// load background
	char backgroundName[256];
	sprintf_s(backgroundName, 256, "background_menu.jpg");
	background.Load(backgroundName);

	// load font
	mFont.Load(24);
	mCursor.Load("gun_cursor.png");

	// load buttons
	mStartButton1.Load("button_on.png", "button_off.png");
	mStartButton1.SetPosition(SVector2(150.0f, 600.0f));
	mStartButton1.SetText("Earth", 0, 162, 232);

	mStartButton2.Load("button_on.png", "button_off.png");
	mStartButton2.SetPosition(SVector2(350.0f, 600.0f));
	mStartButton2.SetText("Moon", 0, 162, 232);

	mStartButton3.Load("button_on.png", "button_off.png");
	mStartButton3.SetPosition(SVector2(550.0f, 600.0f));
	mStartButton3.SetText("Venus", 0, 162, 232);

	mStartButton4.Load("button_on.png", "button_off.png");
	mStartButton4.SetPosition(SVector2(750.0f, 600.0f));
	mStartButton4.SetText("Mars", 0, 162, 232);

	mQuitButton.Load("button_on.png", "button_off.png");
	mQuitButton.SetPosition(SVector2(445.0f, 700.0f));
	mQuitButton.SetText("Quit", 0, 162, 232);

	// load sound
	mTitleMusic.Load("titletheme01.mp3");

	// play music once
	mTitleMusic.Play(true);

	// 0, 162, 232
}

void FrontendState:: Unload()
{
	background.Unload();
	mFont.Unload();
	mCursor.Unload();
	mStartButton1.Unload();
	mStartButton2.Unload();
	mStartButton3.Unload();
	mStartButton4.Unload();
	mQuitButton.Unload();
	mTitleMusic.Unload();
}

NextState FrontendState:: Update(float deltaTime)
{
	mCursor.Update(deltaTime);
	mStartButton1.Update(deltaTime);
	mStartButton2.Update(deltaTime);
	mStartButton3.Update(deltaTime);
	mStartButton4.Update(deltaTime);
	mQuitButton.Update(deltaTime);

	NextState nextState = None;
	if (mStartButton1.IsPressed())
	{
		mGameContext.SetLevel(1);
		nextState = Gameplay;
	}
	else if (mStartButton2.IsPressed())
	{
		mGameContext.SetLevel(2);
		nextState = Gameplay;
	}
	else if (mStartButton3.IsPressed())
	{
		mGameContext.SetLevel(3);
		nextState = Gameplay;
	}
	else if (mStartButton4.IsPressed())
	{
		mGameContext.SetLevel(4);
		nextState = Gameplay;
	}
	else if (mQuitButton.IsPressed())
	{
		nextState = Quit;
	}
	return nextState;
}

void FrontendState:: Render()
{
	background.Render();
	mFont.Print("Destiny 2D", 890, 50);
	mFont.Print("Jordan Lloyd", 870, 100);
	mStartButton1.Render();
	mStartButton2.Render();
	mStartButton3.Render();
	mStartButton4.Render();
	mQuitButton.Render();
	mCursor.Render();
}